package com.dmap.admin.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dmap.admin.constants.PlanTimerConstant;
import com.dmap.admin.service.backgroundv2.UserV2Service;
import com.dmap.base.send.email.MailService;
import com.dmap.schedule.annotation.ElasticJobConf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author guanming
 * @date 18-7-13下午3:26
 * @Description: 每日自动将所有用户登陆错误次数置为0
 */
@ElasticJobConf(name="重置所有用户登陆错误次数为0", cron="0 0 0 * * ?", eventTraceRdbDataSource="datasourcelog")
public class ResetUserLoginWrongNumJob implements SimpleJob {

    private final static Logger logger = LoggerFactory.getLogger(ResetUserLoginWrongNumJob.class);

    @Resource
    private UserV2Service userV2Service;

    @Override
    public void execute(ShardingContext shardingContext) {
        logger.info("--------------------admin服务 每日自动将所有用户登陆错误次数置为0 定时任务方法 开始执行.");
        int countNum = userV2Service.setAllUserLoginWrongNumZero();
        logger.info("admin服务 每日自动将所有用户登陆错误次数置为0 定时任务 countNum : {}", countNum);
        try {
            MailService.sendMail(PlanTimerConstant.EMAIL_ADDRESS, PlanTimerConstant.ADMIN_EMAIL_SUBJECT, new Date() + "admin服务 每日自动将所有用户登陆错误次数置为0 定时任务 countNum : " + countNum);
        } catch (Exception e) {
            logger.error("admin服务 每日自动将所有用户登陆错误次数置为0 定时任务 countNum MailService.sendMail or inetAddress.getHostName() error:  {}", e);
        }
    }
}
